<template>
  <div class="login-container">
    <img height="120" class="logo"  src="../../../static/logo.png" alt="脑健康大数据平台">
    <el-row>
      <el-col :span="14" class="container"><img class="picture box"  src="../../../static/Data_extraction-amico.png" alt="Illustration from Storyset"></el-col>
      <el-col :span="6" class="container">
        <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form box" auto-complete="on" label-position="left">
            <h3  class="title">脑电管理系统</h3>
          <el-form-item class="form-container" prop="username">
            <span class="svg-container">
              <svg-icon icon-class="user" :style="{ transform: `scale(${iconScale})` }"/>
            </span>
            <el-input v-model="loginForm.username" name="username" type="text" auto-complete="on" placeholder="username" />
          </el-form-item>
          <el-form-item class="form-container" prop="password">
            <span class="svg-container">
              <svg-icon icon-class="password"  :style="{ transform: `scale(${iconScale})` }"/>
            </span>
            <el-input
              :type="pwdType"
              v-model="loginForm.password"
              name="password"
              auto-complete="on"
              placeholder="password"
              @keyup.enter.native="handleLogin" />
            <span class="show-pwd" @click="showPwd">
              <svg-icon icon-class="eye" />
            </span>
          </el-form-item>

            <el-button :loading="loading" type="primary" style="width:100%;height: 60rem;margin-bottom: 20rem" @click.native.prevent="handleLogin">
              登入
            </el-button>

    <!--      <el-form-item>-->
    <!--        <el-button :loading="loading" type="primary" style="width:100%;" @click.native.prevent="handleUp">-->
    <!--          注册-->
    <!--        </el-button>-->
    <!--      </el-form-item>-->

        </el-form>
      </el-col>
      <el-col :span="4" class="container"></el-col>
    </el-row>
  </div>
</template>

<script>
import { isvalidUsername } from '@/utils/validate'

export default {
  name: 'Login',
  data() {
    const validateUsername = (rule, value, callback) => {
        callback()
    }
    const validatePass = (rule, value, callback) => {
      if (value.length < 5) {
        callback(new Error('密码不能小于5位'))
      } else {
        callback()
      }
    }
    return {
      loginForm: {
        username: '',
        password: ''
      },
      loginRules: {
        username: [{ required: true, trigger: 'blur', validator: validateUsername }],
        password: [{ required: true, trigger: 'blur', validator: validatePass }]
      },
      loading: false,
      pwdType: 'password',
      redirect: undefined,
      iconScale: 1
    }
  },
  watch: {
    $route: {
      handler: function(route) {
        this.redirect = route.query && route.query.redirect
      },
      immediate: true
    }
  },
  created() {
    let width = document.body.clientWidth;
    console.log(width)
    let fontsize = width / 2203
    document.documentElement.style.fontSize = fontsize + "px"
    this.iconScale = fontsize * 1.3
    console.log(this.iconScale)
  },
  methods: {
    showPwd() {
      if (this.pwdType === 'password') {
        this.pwdType = ''
      } else {
        this.pwdType = 'password'
      }
    },
    handleLogin() {
      this.$refs.loginForm.validate(valid => {
        if (valid) {
          this.loading = true
          this.$store.dispatch('Login', this.loginForm).then(() => {
            this.loading = false
            this.$router.push({ path: this.redirect || '/' })
          }).catch(() => {
            this.loading = false
          })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    handleUp()
    {
      console.log("dfsdf")
      this.$router.push({path:`/signUp`});
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss">
$bg: #ffffff;
$light_gray: #000000;

/* reset element-ui css */
.login-container {
  .el-input {
    display: inline-block;
    height: 55rem;
    font-size: 20rem;
    width: 70%;
    input {
      background: transparent;
      border: 0rem;
      -webkit-appearance: none;
      border-radius: 0rem;
      padding: 12rem 5rem 12rem 15rem;
      color: $light_gray;
      height: 60rem;
      &:-webkit-autofill {
        -webkit-box-shadow: 0 0 0rem 1000rem $bg inset !important;
        -webkit-text-fill-color: #000000 !important;
        height: 55rem;
      }
    }
  }
  .el-form-item {
    border: 1rem solid #afafaf;
    background: rgb(255, 255, 255);
    border-radius: 5rem;
    color: #ff0000;
    font-size: 160px;
  }
}

</style>

<style rel="stylesheet/scss" lang="scss" scoped>
$bg: #ffffff;
$dark_gray: #889aa4;
$light_gray: #000000;
.svg-icon{
}
.el-button{
  font-size: 20rem;
  padding: 20rem 0;
  height: 100%;
  vertical-align: middle;
}
.login-container {
  position: fixed;
  height: 100%;
  width: 100%;
  background-color: $bg;
  .logo{
    width: 20vw;
    height: auto;
    margin-left: 5vw;
    margin-top: 5vh;
  }
  .container{
    display: flex;
    //border-style:solid;
    height: 80%;
    .box{
      //justify-content: center;
      //align-items: center;
      //border-style: solid;
    }
  }
  .login-form {
    left: 0;
    right: 0;
    width: 500rem;
    max-width: 150%;
    padding: 35rem 35rem 15rem 35rem;
    margin-top: 40rem;
    //margin-right: auto;
    margin-left: 30rem;
    //border-style:solid;
    background-color: #efefef;
    border-radius: 3rem;
    border: solid 1rem #afafaf;
  }
  .picture{
    //margin-top: 10px;
    //top:50%;
    margin-left: auto;
    margin-right: 6vw;
    width: 40vw;
    height: auto;
  }
  .tips {
    font-size: 14rem;
    color: #000000;
    margin-bottom: 10rem;
    span {
      &:first-of-type {
        margin-right: 16rem;
      }
    }
  }
  .svg-container {
    padding: 0rem 10rem 0rem 30rem;
    color: $dark_gray;
    display: inline-block;
  }
  .form-container{
  }
  .title-container{

  }
  .title {
    font-size: 34rem;
    font-weight: 400;
    color: $light_gray;
    margin: 0rem auto 20rem auto;
    text-align: center;
    font-weight: bold;
    font-family: "Microsoft YaHei",serif;
  }
  .show-pwd {
    position: absolute;
    right: 10rem;
    top: 7rem;
    font-size: 16rem;
    color: $dark_gray;
    cursor: pointer;
    user-select: none;
  }
  .el-form-item__content{
    height: 3000rem;
  }
}

</style>
